package dummy.test.boundry;

import java.util.HashMap;
import java.util.Map;

import org.annoflow.policy.Policy;
import org.annoflow.policy.boundry.SecureClassPolicy;

@Policy(policy=SecureClassPolicy.class)
public class UserRegistry {

	public static Map<String,User> userProfiles; 
	public static User getUser(String userName)
	{
		return userProfiles.get(userName);
	}
	static
	{
		userProfiles =  new HashMap<String,User>();
		userProfiles.put("Mike",new User("Mike", "foo"));
		userProfiles.put("John",new User("John", "foo"));
		userProfiles.put("Ali",new User("Ali", "foo"));
		userProfiles.put("Sylvia",new User("Sylvia", "foo"));
		userProfiles.put("Alex",new User("Alex", "foo"));
		userProfiles.put("Josh",new User("Josh", "foo"));
		userProfiles.put("Richard",new User("Richard", "foo"));
	}
	public static boolean requestPasswordChange(User internalUser, String oldPassword, String newPassword)
	{
		if(internalUser.getPassword().equals(oldPassword))
		{
			internalUser.setPassword(newPassword);
			return true;
		}
		return false;
	}
	public static User authentcateUser(String userName, String password) {
		User profile = userProfiles.get(userName);
		if(profile.getPassword().equals(password))
		{
			return profile;
		}
		return null;
	}
	public static User addUser(String userName, String password) {
		User user = new User(userName, password);
		userProfiles.put(userName, user);
		return user;
	}
}
